// pages/company/adressinfo/adressinfo.js
const App = getApp()
let AJAX = require("../../../utils/util.js").AJAX
let formatRichText = require('../../../utils/util.js').formatRichText

Page({

  /**
   * 页面的初始数据
   */
  data: {
    adressId:'',
    dataInfo:'',
    markers: [],
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      navH: App.globalData.navHeight,
      adressId:options.id
    })
    this.requestInfo()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  navBack() {
    wx.navigateBack()
  },
  requestInfo(){
    let vm =this
    AJAX("companys/info","GET",{
      id:vm.data.adressId
    }).then(res=>{
      let _data = res.data
      _data.XLoad = _data.lon_lat.split(',')[0]
      _data.YLoad = _data.lon_lat.split(',')[1]
      _data.content = formatRichText(_data.content).replace(/<section/g, '<div').replace(/\/section>/g, '\div>')
      let _arr = [{
        iconPath: '../../../image/posi.png',
        id: 0,
        latitude: _data.YLoad,
        longitude: _data.XLoad,
        width: 20,
        height: 20,
        label: { content: _data.company_name, color: '#333333', fontSize: "12", x: '10', y: "3", borderRadius: "3", bgColor: "#E0FFFB", borderColor: "#5BB3A9", textAlign: "center", padding:"5"}
      }]
      vm.setData({
        dataInfo:_data,
        markers: _arr
      })
    })
  },
  openTap(e){
    let _la = e.currentTarget.dataset.latitude*1
    let _lo = e.currentTarget.dataset.longitude*1
    wx.openLocation({
      latitude: _la,
      longitude: _lo,
    })
  },
  makePhone(e){
    let _phone = e.currentTarget.dataset.phone
    wx.makePhoneCall({
      phoneNumber: _phone,
    })
  },
  wechartTalk(){
    
  }
})